package com.atguigu.spring6.resource;

import org.springframework.core.io.UrlResource;

import java.net.MalformedURLException;

// 演示UrlResource的使用
public class UrlResourceDemo {
    public static void main(String[] args) {
        try {
            loadUrlResource("http://www.baidu.com");
            loadUrlResource("file:atguigu.txt");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void loadUrlResource(String url) throws Exception {
        // 创建一个UrlResource对象
        UrlResource urlResource = new UrlResource(url);
        // 创建一个URL资源
        System.out.println(urlResource.getURL());
        System.out.println(urlResource.getFilename());
        System.out.println(urlResource.getInputStream().read());
    }
}
